﻿using System;
using UnityEngine;
using UnityEngine.UI;

public class EditEduAndLocationUI : MonoBehaviour
{
    public ListTogglesGroup eduGroup;
    public LocationUI locationUI;

    int m_Edu;
    string m_locationProvince;
    string m_locationCity;

    public NextBtn nextBtn;

    public Text locationBtnText;

    internal Action<int,string,string> onEditEnd;

    void OnEnable()
    {
        m_Edu = 0;
        m_locationCity = "";

        eduGroup.Init(OnSelectEdu, -1);
        locationUI.Init(OnSelectCity);
        locationUI.gameObject.SetActive(false);

        nextBtn.onClick = this.OnClickNext;
        nextBtn.SetText("下一步(2/3)");
        nextBtn.Disactive();
    }

    private void OnSelectEdu(int gender)
    {
        m_Edu = gender;

        CheckEnd();
    }

    private void OnSelectCity(string province,string locationCity)
    {
        m_locationProvince = province;
        m_locationCity = locationCity;
        locationBtnText.text = string.IsNullOrEmpty(province) ? locationCity : province + "-" + locationCity;
        locationBtnText.color = Color.black;

        CheckEnd();
    }



    void CheckEnd()
    {
        if (this.m_Edu > 0 && !string.IsNullOrEmpty(m_locationCity))
        {
            nextBtn.Active();
        }
    }

    public void OnClickShowLocationUI() 
    {
        locationUI.gameObject.SetActive(true);
    }

    public void OnClickNext()
    {
        onEditEnd?.Invoke(m_Edu, m_locationProvince, m_locationCity);
    }
}
